package edu.chinasoft.handler;

import edu.chinasoft.domain.Application;
import edu.chinasoft.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

@Controller("applicationHandler")
@RequestMapping("/applicationhandler")
public class ApplicationHandler {
    private ApplicationService applicationService;



    @RequestMapping("/method01.do")
    @ResponseBody
    public String method01(Application application){
        Date date = new Date();
        application.setOpertime(date);
        applicationService.addApplication(application);
        return "success";
    }

    public ApplicationService getApplicationService() {
        return applicationService;
    }
    @Autowired
    @Qualifier(value = "applicationService")
    public void setApplicationService(ApplicationService applicationService) {
        this.applicationService = applicationService;
    }

    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }
}
